﻿#include<iostream>
#include<vector>

class person
{
public:
	person(std::string name, int age)
	{
		this->m_Name = name;
		this->m_Age = age;
	}

	std::string m_Name;
	int m_Age;
};

//存放对象
void test01()
{
	std::vector<person> v;

	person p1("aaa", 10);
	person p2("bbb", 20);
	person p3("ccc", 30);
	person p4("ddd", 40);
	person p5("eee", 50);
	person p6("fff", 60);

	v.push_back(p1);
	v.push_back(p2);
	v.push_back(p3);
	v.push_back(p4);
	v.push_back(p5);
	v.push_back(p6);

	for (std::vector<person>::iterator it = v.begin(); it != v.end(); ++it)
	{
		std::cout << "姓名：" << (*it).m_Name << "\t年龄：" << (*it).m_Age << '\n';
	}
}

//存放对象指针
void test02()
{
	std::vector<person*> v;
	

	person p1("aaa", 10);
	person p2("bbb", 20);
	person p3("ccc", 30);
	person p4("ddd", 40);
	person p5("eee", 50);
	person p6("fff", 60);

	v.push_back(&p1);
	v.push_back(&p2);
	v.push_back(&p3);
	v.push_back(&p4);
	v.push_back(&p5);
	v.push_back(&p6);

	for (std::vector<person*>::iterator it = v.begin(); it != v.end(); ++it)
	{
		std::cout << "姓名：" << (*it)->m_Name << "\t年龄：" << (*it)->m_Age << '\n';
	}
}









int main()
{
	test01();
	std::cout << "-----------------------" << '\n';
	test02();


	return 0;
}
